<template>
	<view class="content">
		<view class="header">
			<view class="fs22 colorf font-weight headers">设置新密码</view>
		</view>
		<view class="comm">
			<view class="title fs18 colorf font-weight">密码</view>
			<view class="edit clear-both">
				<input type="text" class="input float-r colorf fs20" placeholder="请输入密码" placeholder-class="color80A" password="true"/>
			</view>
			<view class="title fs18 colorf font-weight">确认密码</view>
			<view class="edit clear-both">
				<input type="text" class="input float-l colorf fs20" placeholder="请再次输入密码" placeholder-class="color80A"  password="true"/>
			</view>
		</view>
		
		<!--登录按钮-->
		<!--手机号 验证码 都正确 加btnact类-->
		<view class="loginbtn colorFF6 font-weight fs18 text-center">确定</view>
		
		<view class="backlogin">
			<navigator url="../common">
				<image src="../../../static/tabbar/index/return.png" mode="aspectFill" class="backimg vertical"></image>
				<view class="fs16 colorf vertical">返回登录</view>
			</navigator>
		</view>
		
		<!--弹窗-->
		<!--手机号已注册-->
		<image src="../../../static/tabbar/index/phone_yzc.png" mode="aspectFill" class="tkimg middle"></image>
		<!--手机号码无效-->
		<image src="../../../static/tabbar/index/phone_wx.png" mode="aspectFill" class="tkimg middle"></image>
		<!--验证码不正确-->
		<image src="../../../static/tabbar/index/yzm_err.png" mode="aspectFill" class="tkimg middle"></image>
		<!--密码错误-->
		<image src="../../../static/tabbar/index/psword_err.png" mode="aspectFill" class="tkimg middle"></image>
	</view>
</template>

<script>
	import local_userinfo from '@/util/user/local-userinfo.js'
	import vercode from '@/components/vercode/index.vue'
	export default {
		components: {
			vercode
		},
		data() {
			return {
				phoneNo: '',
				password: '',
				code: '',
				codestatus: false,
				codetext: '获取短信码',
				tickcount: 0,
				codeAgainGet: true,
				isPhonelogin: true,
				wantJumpurl: '',
				imgInfo: {
					head: '/static/login/head.png',
					icon_del: '/static/login/icon_del.png',
					icon_pwd_switch: '/static/login/icon_pwd_switch.png'
				},
				transteText: '切换至普通登录',
				
				isQuick:false,
				isFsyzm:false,
			}
		},
		onShow() {
			console.log(1)
			this.$setTitle("嗨焙鲜生·登录")
		},
		onLoad(options) {
			this.wantJumpurl = decodeURIComponent(options.redirect);
		},
		methods: {
			fsyzm(){
				this.isFsyzm=true;
			},
			switchQuick(){
				this.isQuick?this.isQuick=false:this.isQuick=true;
			},
			transteOtherLogin() {
				this.isPhonelogin = !this.isPhonelogin;
				if (!this.isPhonelogin) {
					this.transteText = '切换至手机号登录'

				} else {
					this.transteText = '切换至普通登录'
				}
			},
			verCode() {
				if (this.codeAgainGet) {
					let phone = this.phoneNo
					if (!/^1[2|3|4|5|6|7|8|9][0-9]\d{4,8}$/.test(phone)) {
						return uni.showToast({
							title: '手机号格式错误',
							mask: true,
							duration: 1500,
							icon: 'none'
						});
					}
					this.$refs.vercode.toggleMask(phone);
				}
			},
			changeCodetxt(tickcount) {
				var _this = this
				var dg = null
				_this.codestatus = true
				_this.codeAgainGet = false
				if (!_this.codeAgainGet) {
					var i = tickcount; //服务器传的时间   
					_this.tickcount = tickcount;
					dg = function() {
						if (i >= 0) {
							_this.codetext = i + "s后重新获取";
							_this.tickcount = i;
							i--;
							setTimeout(function() {
								dg();
							}, 1000);
						} else {
							_this.codeAgainGet = true;
							_this.codetext = "重新获取";
						}
					}
					dg();
				}
			},
			loginNow() {
				let phone = this.phoneNo,
					code = this.code,
					pwd = this.password,
					codelogin = false,
					_this = this;
				if (!/^1[2|3|4|5|6|7|8|9][0-9]\d{4,8}$/.test(phone)) {
					return uni.showToast({
						title: '手机号格式错误',
						mask: true,
						duration: 1500,
						icon: 'none'
					});
				}
				if (this.isPhonelogin) {
					codelogin = true;
					if (code.length != 4) {
						return uni.showToast({
							title: '请输入手机验证码',
							mask: true,
							duration: 1500,
							icon: 'none'
						});
					}
				} else if (pwd.length == 0 || pwd.length > 20) {
					return uni.showToast({
						title: '密码错误',
						mask: true,
						duration: 1500,
						icon: 'none'
					});
				}
				uni.showLoading({
					title: '请稍等...',
					mask: true
				})

				let params = {};
				let channel_from;
				// #ifdef H5
				channel_from = "H5"
				// #endif
				// #ifdef MP-WEIXIN
				channel_from = "MP"
				// #endif
				if (codelogin) params = {
					c: 'LoginController',
					m: 'login_Phone',
					phone: phone,
					code: code,
					channel_from: channel_from
				};
				else params = {
					c: 'LoginController',
					m: 'login_Pwd',
					phone: phone,
					pwd: pwd,
					channel_from: channel_from
				};

				this.$request.post({
					data: params,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
				}).then(res => {
					let dt = res;
					if (dt.Status == "ok") {
						let user = {};
						user.userid = dt.Tag.Id;
						user.sessionid = dt.Tag.rediskey;
						user.jzb = dt.Tag.Money;
						user.phone = dt.Tag.Mobile;
						user.vip = dt.Tag.Vip;
						user.vipexpiretime = dt.Tag.VipExpireTime;
						user.headimg = dt.Tag.HeadImage;
						user.loginname = dt.Tag.LoginName;
						user.realname = dt.Tag.RealName;

						local_userinfo.setUserinfo(user)

						let wantJumpurl = _this.wantJumpurl;
						uni.reLaunch({
							url: wantJumpurl
						})
					} else {
						return uni.showToast({
							title: dt.Msg || '登录失败，请稍候重试',
							mask: true,
							duration: 1500,
							icon: 'none'
						})
					}

				}).catch(error => {
					console.log(error)
				})
			}
		},
		directives: {
			focus: {
				inserted: function(el, {
					value
				}) {
					if (value) {
						el.focus();
					}
				}
			}
		}
	}
</script>
<style>
	page {
		height: 100%;
		width: 100%;
		background-color: #00449F;
		}
</style>
<style lang="scss" scoped="scoped">

		.content {
			height: 100%;
			width: 100%;
			position: relative;
			.color80A{color:#80A1CF;font-size:4.2667vw; }
			.tkimg{
				width: 37.334vw;
				height: 10.667vw;
				z-index: 999;
				display: block;
			}
			.header{
				padding: 12vw 0 12.8vw 0;
				position: relative;
				.headers{
					margin-left: 8vw;
				}
			}
			.comm{
				margin: 0 8vw;
				.edit{
					height: 11.7334vw;
					border-bottom: 2upx solid #80A1CF;
					margin-bottom: 4vw;
					.editag{
						width: 12.8vw;
						height: 6.667vw;
						line-height: 6.667vw;
						background: #fff;
						border-radius: 1vw;
						text-align: center;
						margin-top: 2.5332vw;
					}
					.input{
						width: 100%;
						height: 11.2vw;
						line-height: 11.2vw;
					}
					.wjmm{
						margin-top: 2.5332vw; 
						height: 6.667vw;
						line-height: 6.667vw;
					}
					.fsyzm{
						width: 29.334vw;
						height: 7.4667vw;
						line-height: 7.4667vw;
						border: 2upx solid #fff;
						border-radius: 3.73335vw;
						margin-top: 2.13335vw;
					}
					.act{
						color: #80A1CF;
						border: 2upx solid #80A1CF;
					}
				}
			}
			.loginbtn{
				width: 84vw;
				margin: 0 auto;
				background: #80A1CF;
				height: 13.334vw;
				line-height: 13.334vw;
				border-radius: 6.667vw;
				margin-top: 8vw;
			}
			.btnact{
				background: #fff;
			}
			.backlogin{
				margin-top: 8.5664vw;
				margin-left: 8vw;
				height: 5vw;
				line-height: 5vw;
				.backimg{
					width: 5vw;
					height: 5vw;
					margin-right: 1vw;
				}
			}
		}
	
</style>
